<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>全屏</title>
</head>

<body>
    <div>
        <img src="./image/abc.jpg" alt="">
        <input type="button" id="full" value="设置全屏">
        <input type="button" id="cancelFull" value="退出全屏">
        <input type="button" id="isFull" value="是否全屏">
    </div>

    <script>
        /**
         * 1. requestFullScreen 设置全屏
         * 2. cancelFullScreen 退出全屏
         * 3. fullScreenElement 是否全屏
        */

        /**
         * 不同浏览器需要加上前缀识别
         * 1. 谷歌: webkitrequestFullScreen
         * 2. 火狐: mozrequestFullScreen
         * 3. ie: msrequestFullScreen
        */

        window.onload = function () {
            var div = document.querySelector("div");

            document.querySelector("#full").onclick = function () {
                if (div.requestFullScreen) {
                    div.requestFullScreen();
                } else if (div.webkitRequestFullScreen) {
                    div.webkitRequestFullScreen();
                } else if (div.mozRequestFullScreen) {
                    div.mozRequestFullScreen();
                } else if (div.msRequestFullScreen) {
                    div.msRequestFullScreen();
                }
            }
            document.querySelector("#cancelFull").onclick = function () {
                if (document.cancelFullScreen) {
                    document.cancelFullScreen();
                } else if (document.webkitCancelFullScreen) {
                    document.webkitCancelFullScreen();
                } else if (document.mozCancelFullScreen) {
                    document.mozCancelFullScreen();
                } else if (document.msCancelFullScreen) {
                    document.msCancelFullScreen();
                }
            }
            document.querySelector("#isFull").onclick = function () {
                if (document.fullScreenElement || document.webkitFullScreenElement || document.mozFullScreenElement || document.msFullScreenElement) {
                    alert(true);
                } else {
                    alert(false);
                }
            }
        }
    </script>
</body>
</html>
